#! /bin/bash
# 制作电信telechat镜像脚本

INFO_MSG="mf1.1_ms23rc4:v10 0605, accelerate trainning,and replace mindformers/mindformers/models/utils.py"
BASE_IAMGE="harbor.telecom-ai.com.cn/ai-nlp/mf1.1_ms23rc4:v9"
NEW_IAMGE="harbor.telecom-ai.com.cn/ai-nlp/mf1.1_ms23rc4:v10"
CON_NAME="mf1.1_ms23rc4_v9_0605_images"
ORIGINAL_MODEL_DIR="/lgsl_data1/huawei_wz/0601"

#---创建容器：进入容器---
docker run -td -u 0 --name $CON_NAME \
--privileged=true \
--ipc=host \
--net=host \
--device=/dev/davinci0 \
--device=/dev/davinci1 \
--device=/dev/davinci2 \
--device=/dev/davinci3 \
--device=/dev/davinci4 \
--device=/dev/davinci5 \
--device=/dev/davinci6 \
--device=/dev/davinci7 \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver  \
-v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware \
-v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \
-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
-v /var/log/npu/:/usr/slog \
-v /usr/bin/hccn_tool:/usr/bin/hccn_tool \
-v /data01:/data01 \
-v /data02:/data02 \
$BASE_IAMGE /bin/bash 

docker exec -it $CON_NAME /bin/bash
#------

#---拷贝相关文件:容器中执行---
cd /data01/huawei/lpf/build_images/0605
pip uninstall mindspore
pip install mindspore-2.3.0-cp39-cp39-linux_aarch64.whl
mv /lgsl_data/dianxin_telechat/mindformers/mindformers/models/utils.py /lgsl_data/dianxin_telechat/mindformers/mindformers/models/utils.py.bak
cp utils.py /lgsl_data/dianxin_telechat/mindformers/mindformers/models/utils.py
#---

#---推送镜像--
docker exec -i ${CON_NAME} bash -c "echo \"$INFO_MSG\" >  /lgsl_data/dianxin_telechat/mindformers/version"
docker commit -a "lipengfei" -m "${INFO_MSG}" ${CON_NAME}  $NEW_IAMGE
docker push $NEW_IAMGE
#------

#---验证mindspore
export HCCL_CONNECT_TIMEOUT=3600
export HCCL_EXEC_TIMEOUT=5400
export PYTHONPATH=/lgsl_data/dianxin_telechat/mindformers
source /usr/local/Ascend/ascend-toolkit/set_env.sh
bash /data01/huawei/lpf/build_images/test_ms.sh
python /data01/huawei/lpf/build_images/test_ms_2.py
bash /data01/huawei/lpf/build_images/test_run_8_rank.sh
#------

#---清理容器--
docker stop $CON_NAME
docker rm $CON_NAME
#------
